<template>
  <div
        style="width: 100%">
    <span class="tjsqstyle">
      <p class="shenqing">已添加物料
         <!-- 返回按钮 -->
      <el-button type="primary" icon="el-icon-back" size="mini" @click="goback">返回上一页</el-button>
      </p>
      <el-form :model="queryParamsme" ref="queryForm" :inline="true" style="margin-left: 15px" :rules="rules">
        <!-- <el-form-item label="申请名称" >
          <el-input
            v-model="queryParams.pickName"
            placeholder="请输入申请名称"
            clearable
            size="small"
          />
        </el-form-item>
        <el-form-item label="申请月份" prop="planMonth" >
          <el-date-picker
            v-model="queryParams.planMonth"
            type="month"
            format="yyyy-MM"
            value-format="yyyy-MM"
            size="small"
            placeholder="选择月">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="用途" >
          <el-input
            v-model="queryParams.useing"
            placeholder="请输入用途"
            clearable
            size="small"
          />
        </el-form-item> -->

        <el-form-item label="回收单位" prop="depName">
            <el-select size="small" v-model="queryParamsme.deptName" placeholder="请选择回收单位" ref="selectReport">
              <el-option :value="queryParamsme.depId" :label="queryParamsme.deptName" style="width:199px;height:200px;overflow: auto;background-color:#fff">
                <el-tree
                  node-key="id"
                  :default-expanded-keys="[1]"
                  highlight-current
                  :data="reportData"
                  :props="defaultProps"
                  @node-click="handleNodeClickSJ"
                ></el-tree>
              </el-option>
            </el-select>
         </el-form-item>
        <el-form-item label="选择状态" prop="type">
          <el-select
            v-model="queryParamsme.type"
            placeholder="请选择状态"
            clearable
            @change="changesStu"
            size="small">
           <el-option
            v-for="(dict,index) in typeSteps"
            :key="index"
            :label="dict.label"
            :value="dict.value"
            />
          </el-select>
        </el-form-item>

      </el-form>

      <div style="margin-left: 15px;margin-bottom: 15px" >
        <!-- <el-button type="primary"  icon="el-icon-plus" size="mini" @click="choose">选择</el-button> -->
        <!-- <el-button type="danger" icon="el-icon-delete" size="mini">删除</el-button> -->
         <!-- <el-button type="success"  :loading="loading"  icon="el-icon-plus" size="mini" @click="tijiao" style="width: 100px">保存</el-button> -->
      </div>
      </span>
      <el-table v-loading="loading" :data="queryParams" stripe border>
      <el-table-column align="center" type="index" label="序号"  width="55"  />
      <el-table-column align="center" label="日期" property="crtTime" :show-overflow-tooltip="true" >
        <!-- <template slot-scope="scope">
            <el-input type="number" v-model="queryParams.crtTime" placeholder="" @input="keydownBtn(scope.row)"></el-input>
        </template> -->
      </el-table-column>
      <!-- <el-table-column align="center" label="回收单位" property="depName" :show-overflow-tooltip="true" > -->
      <!-- <template slot-scope="scope" v-show="xz">
            <el-input type="text" v-model="scope.row.depName" placeholder="" ></el-input>
          </template>   -->
          <!-- <template slot-scope="scope"> -->
          <!-- <el-dropdown class="el-dropdown-link">
           <el-input v-model="scope.row.depName">
             <i class="el-icon-arrow-down el-icon--right"></i>
           </el-input>
           <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>123456</el-dropdown-item>
              <el-dropdown-item>000000</el-dropdown-item>
              <el-dropdown-item>111111</el-dropdown-item>
           </el-dropdown-menu>
          </el-dropdown> -->
          <!-- <el-form-item label="回收单位" >
          <el-select size="small" v-model="queryParams.wnameSJ" placeholder="请选择回收单位" ref="selectReport">
            <el-option :value="queryParams.depId" :label="queryParams.deptName" style="width:199px;height:200px;overflow: auto;background-color:#fff">
              <el-tree
                highlight-current
                 accordion
                :data="reportData"
                :props="defaultProps"
                @node-click="handleNodeClickSJ"
              ></el-tree>
            </el-option>
          </el-select>
      </el-form-item>
          </template>
      </el-table-column> -->
      <el-table-column align="center" label="地点" property="place" :show-overflow-tooltip="true" >
        <template slot-scope="scope" v-show="xz">
            <el-input type="text" v-model="scope.row.place"></el-input>
          </template>
      </el-table-column>
      <el-table-column align="center" label="物资名称"  property="mname" :show-overflow-tooltip="true" >
        <template v-show="xz" slot-scope="scope">
            <el-input type="text" v-model="scope.row.mname" placeholder></el-input>
          </template>
      </el-table-column>
      <el-table-column align="center" label="规格型号"  property="mmodel" :show-overflow-tooltip="true" >
        <template v-show="xz" slot-scope="scope">
            <el-input type="text" v-model="scope.row.mmodel" :placeholder='scope.row.mmodel'></el-input>
          </template>
      </el-table-column>
      <el-table-column align="center" label="计量"  property="unit" :show-overflow-tooltip="true" >
        <template v-show="xz" slot-scope="scope">
            <el-input type="number" v-model="scope.row.unit" :placeholder='scope.row.unit' @input="keydownBtn(scope.row)"></el-input>
          </template>
      </el-table-column>
      <el-table-column align="center" label="单价"  property="planPrice" :show-overflow-tooltip="true" >
        <template slot-scope="scope">
            <el-input type="number" v-model="scope.row.planPrice" :placeholder="scope.row.planPrice" @input="keydownBtn(scope.row)"></el-input>
          </template>
      </el-table-column>
       <el-table-column align="center" label="数量"  property="demandNumber" :show-overflow-tooltip="true" >
         <template slot-scope="scope">
            <el-input type="number" v-model="scope.row.demandNumber" :placeholder="scope.row.demandNumber" @input="keydownBtn(scope.row)"></el-input>
          </template>
       </el-table-column>
      <el-table-column align="center" label="金额"  property="total" :show-overflow-tooltip="true" >
        <!-- <template slot-scope="scope">
        <span>
          {{(scope.row.demandNumber/1)*(scope.row.planPrice/1)}}
        </span>
        </template> -->
      </el-table-column>
      <el-table-column align="center" label="备注"  property="remarks" :show-overflow-tooltip="true" >
        <template slot-scope="scope">
            <el-input type="text" v-model="scope.row.remarks" :placeholder="scope.row.remarks"></el-input>
          </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        width="400px"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            icon="el-icon-check"
            @click="tijiao(scope.row)">保存</el-button>
        </template>
      </el-table-column>
    </el-table>

  </div>
</template>

<script>
  import request from '@/utils/request'
  export default {
    name: "xzhsFYxg",
    components:{

    },
    data() {
      return {
            //记录分页数据
        localPage:undefined,
        localSize:undefined,
        loading:false,
        bukedianji:false,
        //记录当前row
        currentRow:null,
        reportData:[],
        banzuArr:[],//班组数据
        zjlyArr:[],
        rules: {
          depName: [
            { required: true, message: "回收单位不能为空", trigger: "blur" }
          ],
          type: [
            { required: true, message: "状态值不能为空", trigger: "blur" }
          ],
        },
        queryParams:[{
          crtTime:'',
          depName:'',
          type:'',
          place:'',
          mname:'',
          mmodel:'',
          unit:'',
          planPrice:'',
          demandNumber:'',
          remarks:'',
          total:''
        }
        ],
        queryParamsme:{
          type:'',
          deptName:'',
          id:'',
          wname:'',
          depId:''
        },
         //选择模块
        typeSteps:[
          { value: '1',label: '回收'},
          { value: '2',label: '复用'},
          { value: '3',label: '新品'},
          { value: '4',label: '修复'},
        ],
         // 状态数据字典
        statusOptions: [
          { value: '1',label: '月度计划'},
          { value: '2',label: '临时计划'},
        ],
        //修改参数
        id:null,
        bb:[],
        // addshow:false,
        // transmitData:{},//传给子集的数据
        // shuliangSum:0,//总数量
        // jinesum:0,//总金额
        // tableDataxunz:'',
        // dialogVisible:false,
        // //是否配送
        // statusOptions:[
        //   {value:'1',label:'是'},
        //   {value:'2',label:'否'}
        // ],
        // tableDatajihuaXZ:[],//选中的数据
         // 表单参数
        form: {},
         defaultProps: {
          children: "children",
          label: "deptName"
        },
        //战线区队
        reportData:[],
        arrId:[],
        xiugaiUrl:'/material/apply/addPutStorage',
      };
    },

    created() {
      console.log('接收-采购申请详情',this.$route.query)
      var myDate = new Date();
      var pp =myDate.getMonth()+1;       //获取当前月份(0-11,0代表1月)
      if(pp<9){
        pp = "0"+pp
      }
      var ri = myDate.getDate()
      this.queryParams[0].crtTime = myDate.getFullYear()+'-'+pp+'-'+ri;
      this.XQpage = this.$route.query.page
      this.XQsize = this.$route.query.size
      console.log('接收参数',this.$route.query)
      this.getZhanxin()
      if(this.$route.query.leixing=='put'){
        // this.queryParams = (this.$route.query.pp)
        this.id = this.$route.query.pp[0].id
        this.queryParamsme.deptName = this.$route.query.pp[0].depName
        this.queryParams[0].depName = this.$route.query.pp[0].depName
        this.queryParamsme.type = this.$route.query.pp[0].type
        this.queryParams[0].type = this.$route.query.pp[0].type
        this.Stu()
        this.search()
      }
    },
    computed:{
      xz () {
        return this.$route.query.leixing=='post'
      }
    },
    methods: {

      //查询
      search:function(){
        request({
          url: '/material/reuse/'+this.id,
          method: 'get',
        }).then(response => {
          this.loading=false
          console.log(response.data)
          this.queryParams =[response.data]
          console.log(this.queryParams)
          // for (var i=0;i<this.queryParams.wzPickingApplyInfos.length;i++){
          //   this.queryParams.wzPickingApplyInfos[i].storageNum = this.queryParams.wzPickingApplyInfos[i].storageNum +  this.queryParams.wzPickingApplyInfos[i].demandNum
          // }
        });
      },
         //返回
      goback () {
         this.$router.push({path:'/xzhsFY/zxhsFYlb',query:{page:this.XQpage,size:this.XQsize}});
      },
      // handleNodeClickSJ:function(node){
      //   console.log(node,'node')
      //   this.queryParams.waId = node.id
      //   this.queryParams.wnameSJ = node.wname
      //   this.$refs.selectReport.blur()
      // },
      //计划价修改
      // keydownBtn (row) {
      //   if(row.planPrice<0||row.planPrice==null) {
      //     row.planPrice = 0
      //     this.$message({
      //       type: 'info',
      //       message: '计划价不能为负数'
      //     });
      //   }
      // },
       //获取站线数据
      getZhanxin:function(){
        request({
          url: 'system/dept/treeselectNoTeam',
          method: 'get',
        }).then(response => {
          this.reportData = response.data
          console.log('111',this.reportData)
          // this.reportData.unshift(
          //   {depId:0,deptName:'全部'}
          // )
        });
      },
       //战线区队
       handleNodeClickSJ:function(node){
         console.log(node)
        this.queryParamsme.depId = node.deptId
        this.queryParamsme.deptName = node.deptName
         this.queryParams[0].depId = node.deptId
        this.queryParams[0].depName = node.deptName
        console.log(this.queryParams)
        this.$refs.selectReport.blur()
      },
      //状态改变
      changesStu () {
        this.queryParams[0].type = this.queryParamsme.type
         console.log(this.queryParams.type)
      },
      // 键盘按下事件
      keydownBtn:function(row){
        console.log(row)
        if(row.demandNumber<0){
          row.demandNumber =0
          this.$message({
            type: 'info',
            message: '数量不能小于零'
          });
        }
        if(row.planPrice<0){
          row.planPrice = 0
          this.$message({
            type: 'info',
            message: '单价不能为负数'
          });
        }
        row.total = row.planPrice*row.demandNumber
      },
      tijiao (row) {
        if(this.$route.query.leixing=='put') {
          this.xgSave(row)
        } else if(this.$route.query.leixing=='post') {
          this.xzSave(row)
        }
      },
      //修改保存
      xgSave (row) {
        this.$confirm('确认要保存当前数据吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(()=>{
          console.log(row)
           if(row.depName == ''||row.depName ==null) {
             this.$message({
              type:'warning',
              message:'回收单位不能为空'
            })
            return
          }
          if(row.type==''||row.type==null) {
            this.$message({
              type:'warning',
              message:'状态不能为空'
            })
            console.log(row)
            return
          }
          request({
            url:'/material/reuse/upd',
            method:'put',
            data:row
          }).then((response)=>{
            if(response.code=='200') {
              this.goback()
              this.$message({
                type:'success',
                message:'保存成功'
              })
            }
          })
        })
      },
      //新增保存
      xzSave (row) {
        this.$confirm('确认要保存当前数据吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(()=>{
          if(row.depName == ''||row.depName ==null) {
             this.$message({
              type:'warning',
              message:'回收单位不能为空'
            })
            return
          }
          if(row.type==''||row.type==null) {
            this.$message({
              type:'warning',
              message:'状态不能为空'
            })
            console.log(row)
            return
          }
          request({
            url:'/material/reuse/add',
            method:'post',
            data:row
          }).then((response)=>{
            if(response.code=='200') {
              this.goback()
              this.$message({
                type:'success',
                message:'保存成功'
              })
            }
          })
        })
      },
       Stu () {
        if(this.queryParamsme.type=='1') {
          this.queryParamsme.type = '回收'
        }  else if(this.queryParamsme.type=='2') {
         this.queryParamsme.type = '复用'
        }  else if(this.queryParamsme.type=='3') {
          this.queryParamsme.type = '新品'
        }  else if(this.queryParamsme.type=='4') {
         this.queryParamsme.type = '修复'
        }
      }
      //表格复选框监听
      // handleSelectionChange:function(row){
      //   console.log(row)
      //   this.tableDatajihuaXZ = row
      //   // var arr=[]
      //   // for (var i=0;i<row.length;i++){
      //   //   arr.push(row[i].id/1)
      //   // }
      //   // this.arrId = arr
      //   // console.log('this.arrId ', this.arrId )

      // },
      //类型监听
      // leixingchange:function(row){
      //   console.log('row',row)

      // },
      //修改删除
      // xgshanchu:function(){
      //   this.loading=true
      //   request({
      //     url: '/material/info/delInventoryDetails',
      //     method: 'delete',
      //     data:this.arrId
      //   }).then(response => {
      //     this.search()
      //   });
      // },
      //删除
      // deleteBtn:function () {
      //   for (var i=0;i< this.queryParams.wzPickingApplyInfos.length;i++){
      //     for(var j=0;j<this.tableDatajihuaXZ.length;j++){
      //       if(this.queryParams.wzPickingApplyInfos[i]==this.tableDatajihuaXZ[j]){//相等
      //         this.queryParams.wzPickingApplyInfos.splice(i,1)
      //         this.fuzhiIndex()
      //       }
      //     }
        // }
        // debugger
        // if(this.queryParams.wzPickingApplyInfos.length>0){
        //   this.bukedianji=true
        // }else {
        //   this.bukedianji=false
        // }
      //   this.fuzhiIndex()
      // },
      //重新赋值index
      // fuzhiIndex:function(){
      //   for (var i=0;i<this.queryParams.wzPickingApplyInfos.length;i++){
      //     this.queryParams.wzPickingApplyInfos[i].index =i
      //   }
      // },
        //键盘回车
      // keyupBtn (scope) {
      //   const len = this.queryParams.wzPickingApplyInfos.length
      //   const val = this.currentRow
      //   console.log(val)
      //  this.queryParams.wzPickingApplyInfos.forEach((item,index) =>{
      //     if(item===val) {
      //       if(index<len-1) {
      //         this.$refs['mark' + (index + 1)].focus()
      //       }else {
      //         this.$refs['mark' + (0)].focus()
      //       }
      //     }
      //   })
      // },
      //产品表格监听
      // chanpinonChange(val) {
      //   console.log(val)
      // },
      // //分页
      // handleSizeChange(val) {
      //   console.log(`每页 ${val} 条`);
      // },
      // handleCurrentChange(val) {
      //   console.log(`当前页: ${val}`);
      // },
      // tijiao:function () {

     
      //   // debugger
      //   if(this.queryParams.planMonth==''){
      //     this.$message({
      //       type: 'warning',
      //       message: '申请月份不能为空！'
      //     });
      //     return
      //   }
      //   if(this.queryParams.wnameSJ==''){
      //     this.$message({
      //       type: 'warning',
      //       message: '请选择仓库！'
      //     });
      //     return
      //   }
      //   if(this.queryParams.wzPickingApplyInfos.length<1) {
      //     this.$message({
      //       type: 'warning',
      //       message: '增加的数量不能为零'
      //       });
      //       return
      //   }
      //   for (let i = 0; i < this.queryParams.wzPickingApplyInfos.length; i++) {
      //     if(this.queryParams.wzPickingApplyInfos[i].demandNum<=0||this.queryParams.wzPickingApplyInfos=='') {
      //        this.$message({
      //       type: 'warning',
      //       message: '请填写正确的数量'
      //     });
      //     return
      //     }

      //   }
      //   this.loading = true
      //   request({
      //     url:this.xiugaiUrl,
      //     method: this.leixng,
      //     data:this.queryParams
      //   }).then(response => {
      //     this.loading = false
      //     this.$message({
      //       type: 'success',
      //       message: '操作成功!'
      //     });
      //     this.$router.push({path:'/xzhsFY/xzhsFYlb'});
      //   });

      // },


    }
  };
</script>
<style scoped>
  .tjsqstyle .shenqing{
    color: #05A380;
    font-weight: 700;
    margin-left: 15px;

  }



</style>

